import 'dart:async';
import 'package:flutter/services.dart';

class FlutterBlockchain {
  static const MethodChannel _channel =
      const MethodChannel('flutter_blockchain');

  static Future<String> get platformVersion async {
    final String version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static Future<String> RandomPrivate() async {
    return await _channel.invokeMethod("eos.randomPrivate");
  }

  static Future<String> PrivateToPublic(String private) async {
    return await _channel.invokeMethod(
        "eos.privateToPublic", <String, dynamic>{'private': private});
  }

  static Future<String> PushTransaction(Map<String, dynamic> args) async {
    return await _channel.invokeMethod("eos.pushTransaction", args);
  }

  static Future<bool> Test3Net(bool isTest) async {
    return await _channel.invokeMethod("btc.Test3Net", {"istest": isTest});
  }

  static Future<String> randomMnemonic() async {
    return await _channel.invokeMethod("btc.randomMnemonic");
  }

  static Future<String> segAddress(String mnemonic) async {
    return await _channel.invokeMethod(
        "btc.segAddress", <String, dynamic>{'mnemonic': mnemonic});
  }

  static Future<String> btcTransfer(
      String mnemonic, address, int amount, fee, List<String> utxos) async {
    return await _channel.invokeMethod("btc.transfer", <String, dynamic>{
      'mnemonic': mnemonic,
      'address': address,
      'amount': amount,
      'fee': fee,
      'utxos': utxos,
    });
  }

  static Future<String> ethAddress(String mnemonic) async {
    return await _channel.invokeMethod(
        "eth.address", <String, dynamic>{'mnemonic': mnemonic});
  }

  static Future<String> ethTokenData(String address,int amount) async {
    return await _channel.invokeMethod(
        "eth.tokendata",<String,dynamic>{'address':address,"amount":amount});
  }

  static Future<String> ethTransfer(String mnemonic, address, int chainId,
      int nonce, int gasPrice, int gasLimit,double amount, String data) async {
    return await _channel.invokeMethod("eth.transfer", <String, dynamic>{
      'mnemonic': mnemonic,
      'address': address,
      'chainid': chainId,
      'nonce': nonce,
      'gasprice': gasPrice,
      'gaslimit': gasLimit,
      'amount': amount,
      'data': data,
    });
  }

  static Future<String> randomDCRMnemonic() async{
    return await _channel.invokeMethod("dcr.mnemonic");
  }

  static Future<String> DcrAddress(String mnemonic,String netparam) async{
    return await _channel.invokeMethod("dcr.address",<String,dynamic>{
      'mnemonic':mnemonic,
      'netparam':netparam,
    });
  }

  static Future<String> DcrTransaction(String mnemonic,netparam,address,double amount,List<String> utxos) async{
    return await _channel.invokeMethod("dcr.transaction",<String,dynamic>{
      'mnemonic':mnemonic,
      'netparam':netparam,
      'address':address,
      'amount':amount,
      'utxos':utxos,
    });
  }
}
